<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../zhengcewenjian.css">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<div class="main" style="height: 625px">
    <div class="left" style="width:100px;margin-left:100px;float: left;">
        <div class="card" style="margin-top:20px;height: 350px;width: 250px;">
            <h3 align="center">栏目导航</h3><br>
            <hr style="border:1px solid #ccc;">
            <ul>
                <li><a style="cursor: pointer" onclick="parent.page2('历年本科生创新创业项目')">历年本科生创新创业项目</a></li>
                <hr>
                <li class="this"><a style="cursor: pointer" onclick="parent.page2('历年本科生竞赛获奖')">历年本科生竞赛获奖</a></li>
                <hr>
                <li><a style="cursor: pointer" onclick="parent.page2('历年本科生论文专利软著')">历年本科生论文专利软著</a></li>
                <hr>
            </ul>
            <br>
        </div>
    </div>
    <div class="right">
        <div class="title">
            <h2 style="font-weight: bold;color: #0B469F;">创新创业 | 历年本科生竞赛获奖</h2>
        </div>
        <div id="list" class="list">
        </div>
        <div id="homeworkListPage" style="text-align: center;"></div>
    </div>
</div>
<div id="footer" class="layui-row" style="height: 100px;background-color: #00477A;">
    <div id="link" align="center" lay-separator="|" style="height:50px;line-height: 50px;">
        <a href="#">河北工业大学</a><span>&nbsp&nbsp|&nbsp</span>
        <a href="#">人工智能与数据科学学院</a><span>&nbsp&nbsp|&nbsp</span>
        <a href="#">科研院</a><span>&nbsp&nbsp|&nbsp</span>
        <a href="#">本科生院</a><span>&nbsp&nbsp|&nbsp</span>
        <a href="#">研究生院</a><span>&nbsp&nbsp|&nbsp</span>
        <a href="#">联系我们</a>
    </div>
    <div style="text-align: center;" class="layui-layout-admin layui-footer">
        <p style="color: white">
            COPY RIGHT &copy;&nbsp;&nbsp;&nbsp;天津市北辰区双口镇西平道5340号河北工业大学北辰校区人工智能与数据科学学院知识成果共享平台
            &nbsp;&nbsp;&nbsp;津ICP备350321号
        </p>
    </div>
</div>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script src="../../layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>
    //加载总页数
    var total = 10;
    //localStorage.setItem("position",localStorage.getItem(type));
    //先初始化加载首页，十条数据
    layui.use(['laypage','jquery'], function() {
        showRecord(1,2);
        var laypage = layui.laypage,$ = layui.$;
        // var currentPage = $('.layui-input');
        laypage.render({
            elem: $("#homeworkListPage")
            //注意，这里的 elem 指向存放分页的容器，值可以是容器ID、DOM对象。
            //例1. elem: 'idName' 注意：如果这么写，这里不能加 # 号
            //例2. elem: document.getElementById('idName')
            //例3. elem: $("#idName")
            ,count: total //数据总数，从服务端得到
            , limit: 2                      //默认每页显示条数
            , limits: [1, 2, 3,4,5,6]			//可选每页显示条数
            , curr: 1                     //起始页
            , groups: 4                     //连续页码个数
            , prev: '上一页'                 //上一页文本
            , next: '下一页'                 //下一页文本
            , first: 1                      //首页文本
            , layout: ['prev', 'page', 'next','limit','refresh','skip']

            //跳转页码时调用
            , jump: function (obj, first) { //obj为当前页的属性和方法，第一次加载first为true
                //非首次加载 do something
                if (!first) {
                    //清空以前加载的数据
                    $('#list').empty();
                    //调用加载函数加载数据
                    // console.log(currentPage.val());
                    showRecord(obj.curr,obj.limit);
                }
            }
        });
    })
    function showRecord(pageNo,pageSize) {
        console.log("pageNo", pageNo);
        console.log("pageSize", pageSize);
        var pageRequest = {
            currentPage: pageNo,
            pageSize: pageSize
        };
        $.ajax({
            url: 'http://106.14.215.182:9091/tby/ipos-resouces-file/getfileByResource',
            type: "POST",
            data: JSON.stringify({
                resource: "历年本科生竞赛获奖",
                pageRequest: pageRequest
            }),
            contentType: 'application/json',
            dataType: 'json',
            success: function (result) {
                console.log(result);
                var data = result.data;
                var obj = new Object();
                var tbody = $("#list");
                if (data.records.length === 0) {
                    var temp = '<div class="outPageTip">' + '已经到底，请往前翻页' + '</div>';
                    tbody.append(temp);
                    tbody.innerHTML = temp;
                    // $('.hide-box-out-page-alert')[0].style.display = 'block';
                    return;
                }
                var html1 = '<ul>';
                var html2 = '</ul>';
                var html = '';
                for (var i = 0; i < data.records.length; i++) {
                    obj[i] = data.records[i];
                    localStorage.setItem("fileId" + i, data.records[i].resourceId);
                    if(i==0){
                        html = html+html1;
                    }
                    html = html+ '<li style="margin-bottom: 10px">\n' +
                        '<i class="layui-icon" style="float: left">&#xe623;</i>\n' +
                        '                    <a  onclick="getfile('+i+')">' + obj[i].resourceFileName + '</a>\n' +
                        '                    <p align="right" style="color: #8D8D8D">' + obj[i].time + '</p>\n' +
                        '                </li>\n' +
                        '                <hr>';
                    if(i == data.records.length-1){
                        html = html + html2;
                    }
                }
                tbody.append(html);
                tbody.innerHTML = html;
                form.render();
            }
        })
    }
    function getfile(i){
        var fileId  = localStorage.getItem("fileId"+i);
        $.ajax({
            url:'http://106.14.215.182:9091/tby/ipos-resouces-file/getUrlById',
            data:JSON.stringify({
                id:fileId
            }),
            type:"POST",
            contentType: 'application/json',
            dataType: 'json',
            success:function (result) {
                location.href=result.data.value
            }
        })
    }
</script>
</body>
</html>